package com.teufandsub.socialproximity.logic;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.teufandsub.socialproximity.services.HttpService;

public class AuthenticationInfo {

	public final static String USERNAME_NAME = "username";
	public final static String PASSWD_NAME   = "passwd";
	public final static String REGID_NAME    = "regid";
	
	private String password, username, regid;

	public AuthenticationInfo(String password, String username, String regid) {
		super();
		this.password = password;
		this.username = username;
		this.regid = regid;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getRegid() {
		return regid;
	}

	public void setRegid(String regid) {
		this.regid = regid;
	}

	@Override
	public String toString() {
		return "AuthenticationInfo [password=" + password + ", username="
				+ username + ", regid=" + regid + "]";
	}

	private JSONObject toJSONObject() throws JSONException {
		JSONObject jSonObject = new JSONObject();
		jSonObject.put(USERNAME_NAME, this.username);
		jSonObject.put(PASSWD_NAME, this.password);
		jSonObject.put(REGID_NAME, this.regid);
		
		return jSonObject;
	}
	
	public JSONObject send(Context context) {
		HttpService httpService = new HttpService(context);
		JSONObject ret=null;
		try {
			ret = httpService.authentication(this.toJSONObject());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return ret;
	}
}
